<?php

namespace app\modules\merchant\forms\goods;

use app\common\forms\BaseForm;
use app\utils\UserUtil;

class GoodsForm extends BaseForm{

    public $merchant_id;
    public $goods_id;
    public $cat_id;
    public $goods_name;
    public $goods_desc;
    public $thumbnail;
    public $weight;
    public $price;
    public $count;
    public $is_sale;
    public $sort;
    public $attr_item; //属性集合

    public function scenarios()
    {
        return [
            'create'=>[
                'merchant_id','cat_id','goods_name','goods_desc','thumbnail','weight','price','count','is_sale','sort','attr_item'
            ],
            'update'=>[
                'merchant_id','goods_id','cat_id','goods_name','goods_desc','thumbnail','weight','price','count','is_sale','sort','attr_item'
            ],
        ];
    }

    public function rules()
    {
        return [
            ['merchant_id','default','on'=>['create','update'],'value'=>UserUtil::getModuleUserIdentity("merchant")->getId()],
            ['goods_id','required','on'=>['update'],'message'=>\Yii::t("app","ID不能为空")],
            ['cat_id','required','on'=>['create','update'],'message'=>\Yii::t("app","分类ID不能为空")],
            ['goods_name','required','on'=>['create','update'],'message'=>\Yii::t("app","名称不能为空")],
            ['goods_desc','required','on'=>['create','update'],'message'=>\Yii::t("app","描述不能为空")],
            ['thumbnail','required','on'=>['create','update'],'message'=>\Yii::t("app","图片不能为空")],
            ['weight','required','on'=>['create','update'],'message'=>\Yii::t("app","重量不能为空")],
            ['price','number','skipOnEmpty'=>false,'on'=>['create','update'],'message'=>\Yii::t("app","价格错误")],
            ['count','integer','skipOnEmpty'=>false,'on'=>['create','update'],'message'=>\Yii::t("app","库存错误")],
            ['is_sale','in','range'=>[1,2],'on'=>['create','update'],'skipOnEmpty'=>false,'message'=>\Yii::t("app","显示值错误")],
            ['sort','integer','skipOnEmpty'=>false,'on'=>['create','update'],'message'=>\Yii::t("app","排序错误")],
            ['attr_item','safe','on'=>['create','update']]
        ];
    }
}